package com.books.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.books.controller.utils.R;
import com.books.service.IBookService;
import com.books.vo.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@ResponseBody
public class BookController {


    @Autowired
    IBookService iBookservice;



    @GetMapping("/page_1")
    public R a() {
        IPage<Book> page_1 = iBookservice.getPage_1(1, 1);
//        for(Book book : page_1) {
//            System.out.println(book.toString());
//        }
        R r = new R();
        r.Success(page_1,(int)page_1.getPages());

        return  r;
    }

    @GetMapping("/page_2")
    public R b() {
        List<Book> books = iBookservice.getPage_2(1, 1);
        for(Book book : books) {
            System.out.println(book.toString());
        }
        R r = new R();
        r.Success(books,books.size());
        return  r;
    }
}

